package com.kyzh.core.activities

import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import com.gushenge.core.base.Base
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.dao.GlobalKeys
import com.gushenge.core.dao.MMKVConsts
import com.gushenge.core.requests.UserRequest
import com.kyzh.core.R
import com.kyzh.core.databinding.ActivityMyassetsBinding
import com.kyzh.core.databinding.ItemSettingsV3Binding
import com.kyzh.core.utils.httpSign
import com.kyzh.core.utils.startActivity
import com.kyzh.core.utils.time

class MyAssetsActivity : BaseActivity() {
    private lateinit var binding:ActivityMyassetsBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this,R.layout.activity_myassets)
    }

    override fun onResume() {
        super.onResume()
        initView()
    }
    private fun initView() {
        UserRequest.myAssets {
            binding.also {
                it.vCoin.setInfo(R.drawable.ic_myassets_coin,getString(R.string.ptb),coin)
                it.vCoin.root.setOnClickListener {
                    this@MyAssetsActivity.startActivity<BrowserActivity>(GlobalKeys.TITLE to getString(R.string.ptbRecharge), GlobalKeys.LINK to "${Base.BASEURLV3}/?ct=coin&uid=${MMKVConsts.uid}&t=$time&sign=${httpSign(MMKVConsts.uid)}")
                }
                it.vCoupon.setInfo(R.drawable.ic_myassets_coupon,getString(R.string.coupon),String.format(getString(R.string.couponNum),coupon))
                it.vCoupon.root.setOnClickListener {
                    startActivity<MyCouponActivity>()
                }
                it.vGift.setInfo(R.drawable.ic_myassets_gift,getString(R.string.gift),String.format(getString(R.string.giftNum),lb))
                it.vGift.root.setOnClickListener {
                    startActivity<MyGiftActivity>()
                }
                it.vTiedMoney.setInfo(R.drawable.ic_myassets_tiedmoney,getString(R.string.tiedMoney), String.format(getString(R.string.gameNum),bind))
                it.vTiedMoney.root.setOnClickListener {
                    startActivity<TiedMoneyActivity>()
                }
                it.vPoint.setInfo(R.drawable.ic_myassets_point,getString(R.string.pointText),points)
                it.vPoint.root.setOnClickListener {
                    startActivity<PointsMallActivity>()
                }
                it.vMyDh.setInfo(R.drawable.ic_myassets_order,getString(R.string.exchangedProduct), String.format(getString(R.string.productNums),order))
                it.vMyDh.root.setOnClickListener {
                    startActivity<MyOrderActivity>()
                }
            }
        }
    }

    private fun ItemSettingsV3Binding.setInfo(icon:Int,title:String,  desc:String=""){

        this.tvStart.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(this@MyAssetsActivity,icon),null,null,null)
        this.text = title
        this.desc = desc
    }
}